package net.lzzy.practices.entities;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author 渊何
 */
@Entity
@Getter
@Setter
public class Chapter extends BaseEntity {
    private String name;
    private String description;
    private boolean open;
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    @ManyToOne
    private Course course;

    @OneToMany(mappedBy = "chapter")
    private List<Question> questions = new ArrayList<>();

    public Chapter() {
        createTime = new Date();
        updateTime = createTime;
    }

    @JsonManagedReference
    public List<Question> getQuestions() {
        return questions;
    }

    @JsonBackReference
    public Course getCourse() {
        return course;
    }
}
